<template>
  <div class="goods">
    <div class="item" v-for="(item, index) in goodsList" :key="item.id">
      <img :src="item.imgUrl" />
      <div class="right">
        <p>{{ item.title }}</p>
        <div class="pri_count">
          <span>￥{{ item.price.toFixed(2) }}</span>
          <p>
            <span @click="changeCount({ n: -1, index })">-</span>
            <span>{{ item.count }}</span>
            <span @click="changeCount({ n: 1, index })">+</span>
          </p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import { mapState, mapMutations } from "vuex";

export default {
  methods: {
    ...mapMutations(["changeCount"]),
  },
  computed: {
    ...mapState(["goodsList"]),
  },
};
</script>

<style lang="scss" scoped>
.goods {
  flex: 1;
  padding: 20px;

  .item {
    display: flex;
    margin-bottom: 20px;
    border: 2px solid transparent;
    border-radius: 4px;
    display: flex;
    height: 204px;

    &:hover {
      border: 2px solid tomato;
    }

    img {
      width: 200px;
      height: 200px;
      object-fit: cover;
      border-radius: 4px;
      margin-right: 10px;
    }

    .right {
      flex: 1;
      display: flex;
      flex-direction: column;
      justify-content: space-between;
      padding-right: 20px;

      > p {
        font-size: 24px;
        font-weight: 600;
      }

      .pri_count {
        display: flex;
        justify-content: space-between;

        > span {
          color: tomato;
          font-weight: 600;
          font-size: 20px;
        }

        p {
          display: flex;
          align-items: center;

          span:not(:nth-child(2)) {
            background: #eee;
            border: 1px solid #ccc;
            width: 30px;
            line-height: 28px;
            border-radius: 4px;
            cursor: pointer;

            &:active {
              background: #ccc;
              color: #333;
            }
          }

          span {
            padding: 0 10px;
            height: 30px;
            text-align: center;
            line-height: 30px;
          }
        }
      }
    }
  }
}
</style>
